package bysj.dao;

import bysj.domain.GraduateProjectTrueness;
import util.JdbcHelper;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class GraduateProjectTruenessDao {
    private static GraduateProjectTruenessDao graduateProjectTruenessDao = new GraduateProjectTruenessDao();

    private GraduateProjectTruenessDao() {
    }
    public static GraduateProjectTruenessDao getInstance() {
        return graduateProjectTruenessDao;
    }
    public GraduateProjectTrueness find(Integer id, Connection connection) throws SQLException {
        //创建GraduateProjectType对象
        GraduateProjectTrueness graduateProjectTrueness = new GraduateProjectTrueness(id,"description", "no", "remarks");
        //创建sql语句
        String graduateProjectType_sql = "SELECT * FROM ProjectTrueness WHERE id = ?";
        //创建预编译对象
        PreparedStatement pstmt= connection.prepareStatement(graduateProjectType_sql);
        //为预编译对象赋值
        pstmt.setInt(1,id);
        //获得结果集对象
        ResultSet resultSet = pstmt.executeQuery();
        while(resultSet.next()){
            //为graduateProjectType对象的description赋值
            graduateProjectTrueness.setDescription(resultSet.getString(2));
            //为graduateProjectType对象的no赋值
            graduateProjectTrueness.setNo(resultSet.getString(3));
            //为graduateProjectType对象的remarks赋值
            graduateProjectTrueness.setRemarks(resultSet.getString(4));
        }
        //关闭三个资源
        JdbcHelper.close(resultSet, pstmt);
        return graduateProjectTrueness;
    }
}
